<?php
include('./adm_header.php');
?>
			<div id="content">
				<?php
				if (isset($_GET['p']))
				{
					if (empty($_GET['p']))
					{
						echo 'There is no page specified to edit, please return <a href="./index.php">home</a>.';
					}
					else
					{
						// Check for file existance:
						if (file_exists('../pages/' . $_GET['p']))
						{
							if (isset($_POST['submit']))
							{
								$body = str_replace(array('\\'), array(''), $_POST['body']);
								$title = str_replace(array('\\'), array(''), $_POST['title']);
								// Delete the previous page:
								unlink('../pages/' . $_GET['p']);
								// Create the new page:
								$fh = fopen('../pages/' . $_POST['title'], 'w');
								fclose($fh);
								// Write the data to the new page.
								$fh = fopen('../pages/' . $_POST['title'], 'w');
								fwrite($fh, $_POST['body']);
								fclose($fh);
								echo '<p style="color: green; font-weight: bold;">Page Edited successfully.</p>';
							}
						?>
				<p>When editing a page all HTML is enabled. The number in front of the Page Title is the Order of the Page, if the Page title and order number are the same as another existing page then that page will be overwritten.</p>
				<form action="editpage.php?p=<?php echo $_GET['p']; ?>" method="post">
					<strong>Title and Page Order:</strong><br />
					<input type="text" name="title" value="<?php echo $_GET['p']; ?>" style="width: 600px; font-family: Verdana; font-size: 12px;"><br />
					<strong>Page Content:</strong><br />
					<textarea name="body" style="width: 600px; height: 400px; font-family: Verdana; font-size: 12px;"><?php $body = str_replace(array('\\'), array(''), file_get_contents('../pages/' . $_GET['p'])); echo $body; ?></textarea><br />
					<input type="submit" name="submit" value="Save Changes">
				</form>
						<?php
						}
						else
						{
							echo 'The page specified does not exist, please return <a href="./index.php">home</a>.';
						}
					}
				}
				else
				{
					echo 'There is no page specified to edit, please return <a href="./index.php">home</a>.';
				}
				?>
			</div>
		</div>
	</body>
</html>